// Copyright 2021 Guoyoko. All Rights Reserved.


#include "Node/CustomizeFlowTaskNode.h"

UCustomizeFlowFlowTaskNode::UCustomizeFlowFlowTaskNode(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer),
	Result(ECusFTaskResult::Idle)
{
	ParentNodes.Empty();
	ChildNodes.Empty();
}

void UCustomizeFlowFlowTaskNode::BeginTask()
{
	Result = ECusFTaskResult::InProgress;
	ReceiveBeginTask();
	
}

void UCustomizeFlowFlowTaskNode::TickTask(float DeltaTime)
{
	ReceiveTickTask(DeltaTime);
}

void UCustomizeFlowFlowTaskNode::EndTask()
{
	ReceiveEndTask();
}

void UCustomizeFlowFlowTaskNode::OnTaskFinished(ECusFTaskResult InTaskResult)
{
	Result = InTaskResult;
}

void UCustomizeFlowFlowTaskNode::Reset()
{
	ParentNodes.Reset();
	ChildNodes.Reset();
	Result = ECusFTaskResult::Idle;
}

void UCustomizeFlowFlowTaskNode::AddParentNode(UCustomizeFlowFlowTaskNode* InParentNode)
{
	ParentNodes.AddUnique(InParentNode);
}

void UCustomizeFlowFlowTaskNode::AddChildNode(UCustomizeFlowFlowTaskNode* InChildNode)
{
	ChildNodes.AddUnique(InChildNode);
}

void UCustomizeFlowFlowTaskNode::GetChildNodes(TArray<UCustomizeFlowFlowTaskNode*>& OutChildNodes)
{
	for (auto* TempNode : ChildNodes)
	{
		OutChildNodes.AddUnique(TempNode);
	}
}

void UCustomizeFlowFlowTaskNode::GetParentNodes(TArray<UCustomizeFlowFlowTaskNode*>& OutParNodes)
{
	for (auto* TempNode : ParentNodes)
	{
		OutParNodes.AddUnique(TempNode);
	}
}

